

def fun():
    stream=None
    try:
        a=int(input("请输入一个数字"))
        b= int(input("请输入一个数字"))
        c=a/b
        print(c)
        stream=open("dfdf.txt")
    except ZeroDivisionError:
        print("除数不能为0")
    except ValueError:
        print("必须为数字")
    except Exception as err:
        print(err)#打印错误原因
    finally:
        if stream:
            stream.close()
        pass
    print('----------')

# fun()


def fun2():
    try:
        return 1
    except:
        return 2
    finally:
        return 3

# print(fun2()) #3 finally 一定会执行


# 抛出异常
def fun3():
    username=input('用户名')
    if len(username)<6:
        raise Exception("用户名小于6位")
    else:
        print(username)

def test_fun3():
    try:
        fun3()
    except Exception as err:
        print(err)
test_fun3()

